package officail

import (
	"github.com/gin-gonic/gin"
	"server/src/global"
	"server/src/model/response"
	"server/src/server"
	"strconv"
)

type OfficailGuess struct {
	errMsg string
}

// 获取宾果答案
func (g *OfficailGuess) GetBgAnswerNumber(c *gin.Context) {
	answerId, err := strconv.Atoi(c.Query("answerid"))
	if answerId == 0 || err != nil {
		answerId = global.BG_INITIAL_ANSWERID
	}
	//查找数据库
	resInfo, err := server.ServerGuess.GetBgAnswerNumber(answerId)
	if err != nil {
		global.GVL_LOG.Error("获取宾果答案失败", err)
		response.FailWithMessage("查看失败，请稍后再试", c)
		return
	}
	response.OkWithData(resInfo, c)
}

// 获取前30期的历史数据
func (g *OfficailGuess) GetBgAnswerNumHistory(c *gin.Context) {
	//查找数据库
	resInfo, err := server.ServerGuess.GetBgAnswerNumHistory()
	if err != nil {
		global.GVL_LOG.Error("获取宾果答案失败", err)
		response.FailWithMessage("查看失败，请稍后再试", c)
		return
	}
	response.OkWithData(resInfo, c)
}

// 获取长龙
func (g *OfficailGuess) GetBgChangLong(c *gin.Context) {
	//接收数据
	key := c.Query("type_key")
	value, _ := strconv.Atoi(c.Query("type_value"))
	//查找数据库
	resInfo := server.ServerGuess.GetBgChangLong(key, value)

	response.OkWithData(resInfo, c)
}

// 获取当前期数和下一期数和现在的时间
func (g *OfficailGuess) GetBgGameInfo(c *gin.Context) {
	respInfo := &response.BgGameInfo{
		WaitTime:        global.BG_GAME_RUN_WAIT_TIME,
		OpenTime:        global.BG_GAME_RUN_OPEN_TIME,
		CurrentAnswerId: global.BG_CURRENT_ANSWERID,
		NextAnswerId:    global.BG_NEXT_ANSWERID,
	}
	response.OkWithData(respInfo, c)
}
